-- By: Moieo
local lspconfig = require("lspconfig")
local navic = require("nvim-navic")
local servers_config = require("lsp.servers")

require("mason").setup({
  ui = {
    icons = {
      package_installed = "✓",
      package_pending = "➜",
      package_uninstalled = "✗",
    },
  },
})

-- Mappings.
local function on_attach(client, bufnr)
  navic.attach(client, bufnr)
  require("keybindings").map_lsp(bufnr)
end

-- Setup lspconfig.
require("mason-lspconfig").setup({
  ensure_installed = servers_config.ensure_installed,
})

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.offsetEncoding = { "utf-16" }

-- 配置语言服务器
for _, server in ipairs(servers_config.servers) do
  local config = servers_config.load_config(server, on_attach, capabilities)
  lspconfig[server].setup(config)
end

-- 加载其他 LSP 相关配置
require("lsp.handlers").setup()
require("lsp.cmp")
